package com.cpit.platform.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import com.cpit.platform.config.GlobalConfig;

@SuppressWarnings("deprecation")
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
//		registry.addViewController("/").setViewName("index");
		registry.addViewController("/" + GlobalConfig.WORK_PROJECT_NAME + "/login").setViewName("/" + GlobalConfig.WORK_PROJECT_NAME + "/login");
	}
	
	@Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry){
		registry.addResourceHandler("/ckfinder/**").addResourceLocations("classpath:/static/ckfinder/");
		registry.addResourceHandler("/ckf/**").addResourceLocations("file:D:/tmpFolder/");

		super.addResourceHandlers(registry);
	}
//	@Bean
//	public ErrorPageRegistrar errorPageRegistrar() {
//		return new MyErrorPageRegistrar();
//	}
//
//	private static class MyErrorPageRegistrar implements ErrorPageRegistrar {
//
//		@Override
//		public void registerErrorPages(ErrorPageRegistry registry) {
//			registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400.html"));
//			registry.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403.html"));
//			registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.html"));
//			registry.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.html"));
//		}
//
//	}

}
